package com.wen.service.impl;

import com.github.pagehelper.PageHelper;
import com.wen.dao.MemberMapper;
import com.wen.dao.OrdersMapper;
import com.wen.dao.ProductMapper;
import com.wen.pojo.Member;
import com.wen.pojo.Orders;
import com.wen.pojo.Product;
import com.wen.pojo.Traveller;
import com.wen.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 温加璐
 * 订单se rvice
 */
@Service
@Transactional
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public List<Orders> findAll(int page, int size) throws Exception {
        /**
         * 从那页开始一页显示多少条
         * 参数pageNum是页码值 参数pageSize 代表是每页显示条数
         */
        PageHelper.startPage(page, size);
        return ordersMapper.findAll();
    }

    @Override
    public Orders findById(int id) throws Exception {
        return ordersMapper.findById(id);
    }

    @Override
    public int deleteById(int id) throws Exception {
        ordersMapper.deleteOrder_TravellerById(id);
        return ordersMapper.deleteById(id);
    }

    @Override
    public List<Product> findAllProduct() throws Exception {
        return productMapper.findAll();
    }

    @Override
    public List<Member> findAllMember() throws Exception {
        return memberMapper.findAll();
    }

    @Override
    public int add(Orders orders) throws Exception {
        return ordersMapper.add(orders);
    }

    @Override
    public int addTraveller(Traveller traveller) {
        return ordersMapper.addTraveller(traveller);
    }

    @Override
    public int addOrderTraveller(int orderId, int travellerId) {
        return ordersMapper.addOrderTraveller(orderId, travellerId);
    }

    @Override
    public int findIdByOrderNum(String orderNum) throws Exception {
        return ordersMapper.findIdByOrderNum(orderNum);
    }

    @Override
    public void edit(Orders order) {
        ordersMapper.edit(order);
    }

}
